import config from './config'

// 封装功能函数进行ajax请求
// 默认参数 data为空对象,方法为GET
// 返回promise对象
export default (url, data = {}, method = 'GET') => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: config.url + url,
            data,
            method,
        //  header: {'cookie': wx.getStorageSync('cookie') ? wx.getStorageSync('cookie').find(item=>item.indexOf('MUSIC_U')!==-1):''},

          header: { 'cookie': wx.getStorageSync('cookie') ? wx.getStorageSync('cookie').find((item) => {return item.indexOf('MUSIC_U') !== -1}) : '' },
            success: function (res) {
              // 只有是登录请求时才会存贮cookie
              if(data.isLogin){
                wx.setStorageSync('cookie', res.cookies)
              }
                resolve(res.data)
            },
            fail: function (err) {
                //console.log(err)
                reject(err)
            }
        })
    })
}